package com.woniuxy.company5.service.impl;

import com.woniuxy.company5.dto.LRepProgressDto;
import com.woniuxy.company5.entity.RepDistribution;
import com.woniuxy.company5.entity.RepProgress;
import com.woniuxy.company5.mapper.RepDistributionMapper;
import com.woniuxy.company5.mapper.RepProgressMapper;
import com.woniuxy.company5.service.RepProgressService;
import com.woniuxy.company5.vo.LRepDistributionVo;
import com.woniuxy.company5.vo.LRepProgressVo;
import com.woniuxy.company5.vo.RepDistributionVo;
import com.woniuxy.company5.vo.RepProgressVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class RepProgressServiceImpl implements RepProgressService {
    @Resource
    private RepProgressMapper  repProgressMapper;
    @Resource
    private RepDistributionMapper repDistributionMapper;
    @Override
    public List<RepProgressVo> selAllReps() {
        return repProgressMapper.selAllReps();
    }

    @Override
    public List<RepProgressVo> selByNum(String num) {
        return repProgressMapper.selByNum(num);
    }

    @Override
    public List<LRepProgressVo> selectByLike(LRepProgressDto repProgressDto) {
        return repProgressMapper.selectByLike(repProgressDto);
    }

    @Override
    public int deleteByPrimaryKey(Long id) {
        return repProgressMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(RepProgress record) {
        return repProgressMapper.insert(record);
    }

    @Override
    @Transactional
    public int insertSelective(LRepDistributionVo repDistributionVo) {
        RepDistribution repDistribution = repDistributionMapper.selectByPrimaryKey((long) repDistributionVo.getId());
        repDistribution.setBeiyong1("已接单");
        repDistributionMapper.updateByPrimaryKeySelective(repDistribution);
        RepProgress repProgress = new RepProgress();
        repProgress.setNum(Integer.parseInt(repDistributionVo.getNum()));
        repProgress.setEngineerId(repDistributionVo.getEngineerId());
        repProgress.setCustomerId(repDistributionVo.getCustomerId());
        repProgress.setDeadline(repDistributionVo.getDeadline());
        repProgress.setProgress("0%");
        repProgress.setBeiyong1(repDistributionVo.getCompanyId()+"");
        repProgress.setBeiyong2("1");
        return repProgressMapper.insertSelective(repProgress);
    }

    @Override
    public RepProgress selectByPrimaryKey(Long id) {
        return repProgressMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(RepProgress record) {
        return repProgressMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(RepProgress record) {
        return repProgressMapper.updateByPrimaryKey(record);
    }
}
